package com.bms.dao.impl;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.bms.dao.InitDao;

/**
 * @author Lan
 * @Company 上海全景数字技术有限公司
 */
@Repository
public class InitDaoImpl implements InitDao {

	protected SessionFactory sessionFactory;
	
	@Resource
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	protected Session getSession() {
		return sessionFactory.getCurrentSession();
	}
	
	public Integer delete(String hql) {
		Query q = getSession().createQuery(hql);
		return q.executeUpdate();
	}

	public Integer delete(final String hql, final Object... values) {
		Query q = getSession().createQuery(hql);
		
		if (values != null && values.length > 0) {
			for (int i = 0; i < values.length; i++) {
				q.setParameter(i, values[i]);
			}
		}
		return q.executeUpdate();
	}

}
